package com.test.test2.service.serviceImpl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.test2.dao.mapper.EmployeeMapper;
import com.test.test2.dao.pojo.Employee;
import com.test.test2.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;
    @Override
    public void addEmp(Employee employee) {
       employeeMapper.insert(employee);
    }

    @Override
    public void delEmp(long id) {
        employeeMapper.deleteById(id);
    }

    @Override
    public Employee updateEmpById(Employee employee) {
        employeeMapper.updateById(employee);
        Employee updateEmp = employeeMapper.selectById(employee.getId());
        return updateEmp;
    }

    @Override
    public List<Employee> findAll() {
        List<Employee> employees = employeeMapper.selectList(null);
        return employees;
    }

    @Override
    public Employee findById(long id) {
        Employee employee = employeeMapper.selectById(id);
        return employee;
    }

    @Override
    public Page<Employee> searchDpEmp(long currentPage, long pageSize) {
        Page<Employee> page = new Page<>(currentPage,pageSize);
        Page<Employee> employeePage = employeeMapper.selectPage(page, null);
        return employeePage;
    }
}
